package com.jkc.xh.adapters;

import android.view.View;
import android.view.ViewGroup;

import com.jkc.xh.R;
import com.jkc.xh.adapters.core.BaseRecyclerAdapter;
import com.jkc.xh.adapters.viewholder.HaltSellItemView;
import com.jkc.xh.adapters.viewholder.HaltSellItemView_;
import com.jkc.xh.models.HaltSellModel;

/**
 * 策略列表
 */
public class HaltSellListAdapter extends BaseRecyclerAdapter<HaltSellModel, HaltSellItemView> implements BaseRecyclerAdapter.OnItemClickListener{
    private View currentView = null;
    @Override
    protected HaltSellItemView onCreateItemView(ViewGroup parent, int viewType) {
        return HaltSellItemView_.build(parent.getContext());
    }

    @Override
    protected void onBindView(HaltSellItemView itemView, HaltSellModel model, int position) {
        itemView.bind(model);
    }

    public void setListener(OnViewClickListener listener) {
        addOnViewClickListener(R.id.btnBuy, listener);
    }

    @Override
    public void onItemClick(View view, Object object, int position) {
        {
            if (currentView == null) {
                currentView = view;
            } else {
                if (currentView == view) {
                    ((HaltSellItemView) currentView).disableMoreOption();
                    currentView = null;
                    return;
                }
                ((HaltSellItemView) currentView).disableMoreOption();
                currentView = view;
            }
            ((HaltSellItemView) currentView).showMoreOption();
        }
    }
}
